<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/static/common/taglib.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>消息管理</title>
    <%@include file="../../public/commonCss.jsp" %>
    <%@include file="../../public/commonJs.jsp" %>
</head>
<body ms-controller="main" class="ms-controller">
<div id="wrapper">
    <div class="boxmain whiteBox lrbox">
        <div class="lrboxleft borderR" style="width:70%">
            <div class="from-header borderB contentbox">
                <div>
                    <span class="font14"> 所属分类:</span><a id="category"><span class=" fontOrange2">已发布</span></a>
                </div>
            </div>
            <div class="from-body withheader contentbox " style=" overflow: auto;">
                <table class="layui-table">
                    <thead>
                    <tr>
                        <th>行号</th>
                        <th>apk版本</th>
                        <th>应急手册版本</th>
                        <th>apk下载</th>
                        <th>是否强制</th>
                        <th>描述</th>
                        <th>创建时间</th>
                        <th>删除</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr ms-repeat="tableData">
                        <td>{{$index+1}}</td>
                        <td>{{el.apkVersion}}</td>
                        <td>{{el.emVersion}}</td>
                        <td><a ms-attr-href="el.apkUrl" style="color: blue">{{el.apkName}}</a></td>
                        <td>{{el.isForce=='0'?"否":"是"}}</td>
                        <td ms-attr-title="el.description">{{el.description|truncate(30)}}</td>
                        <td>{{el.createTime}}</td>
                        <td>
                            <div class="tableText">
                                <a href="javascript:;" class="operate del" title="删除"
                                   ms-on-click="deleteRecord(el)"></a>
                            </div>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="lrboxmain borderL" style="margin-left:70%">
            <div class="from-header borderB">
                <span class="fontOrange2">上传APK</span>
            </div>
            <div class="from-body withheader contentbox8 layui-form layui-form-pane" style=" overflow: auto;">
                <div style="width: 100%;;float: left">
                    <div class="layui-form-item">
                        <label class="layui-form-label">apk版本</label>
                        <div class="layui-input-block">
                            <input type="text" name="apkVersion" placeholder="apk版本" class="layui-input"
                                   lay-verify="required"
                                   style="width: 100%;">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">应急版本</label>
                        <div class="layui-input-block">
                            <input type="text" name="emVersion" placeholder="应急手册版本号" class="layui-input"
                                   lay-verify="required"
                                   style="width: 100%;">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <input type="file" name="file" id="file1" class="layui-upload-file" lay-title="上传apk">
                        <span id="apkFile">
                            <span id="apkName"></span>
                            <input type="hidden" name="apkUrl">
                            <input type="hidden" name="apkName">
                            <button class="layui-btn layui-btn-primary layui-btn-small" title="删除"
                                    onclick="deleteCover()">
                                <i class="layui-icon" style="font-size: 30px;">&#xe640;</i>
                            </button>
                        </span>
                    </div>
                    <div class="layui-form-item" pane="">
                        <label class="layui-form-label">是否强制</label>
                        <div class="layui-input-block">
                            <input type="radio" name="isForce" value="1" title="是" checked>
                            <input type="radio" name="isForce" value="0" title="否">
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text tt1">
                        <label class="layui-form-label">描述</label>
                        <div class="layui-input-block">
                            <textarea placeholder="请输入描述" name="description" class="layui-textarea"
                                      style="width: 100%;" lay-verify="required"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit="" lay-filter="demo1">提交</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- whitebox -->
</div>
<script type="text/javascript">
    var vm;
    avalon.ready(function () {
        vm = avalon.define({
            $id: "main",
            tableData: []
        });
        avalon.scan();
        $("#apkFile").hide();
        loadTableData();
    });
    //删除记录
    function deleteRecord(el) {
        layui.layer.alert('你确定删除该版本么?', {
            title: '提醒',
            btn: ['确定', '取消']
        }, function () {
            //执行删除的ajax
            $.ajax({
                type: 'post',
                url: '${ctx}/apkController/deleteObject.action?id=' + el.id,
                data: "",
                dataType: "json",
                timeout: 10000,
                success: function (data) {
                    if (data.code == 0) {
                        layui.layer.msg('删除成功', {icon: 1});
                        loadTableData();
                    } else if (data.code == -1) {
                        layui.layer.msg('删除失败,请重试', {icon: 2});
                    }

                }
            });
        });

    }
    function loadTableData() {
        $.ajax({
            type: 'post',
            url: '${ctx}/apkController/selectAllApkList.action',
            data: "",
            dataType: "json",
            timeout: 10000,
            success: function (data) {
                if (data.code == 0) {
                    vm.tableData = data.data;
                }
            }
        });
    }
    layui.upload({
        url: '${ctx}/apkController/uploadApk.action', //上传接口
        ext: 'apk',
        type: 'file',
        elem: '#file1',
        success: function (res) { //上传成功后的回调
            if (res.code == 0) {
                $("#apkFile").show();
                $("#apkName").text(res.data.title);
                $("input[name='apkUrl']").val(res.data.src);
                $("input[name='apkName']").val(res.data.title);
            }
        }
    });
    function addUser() {
        layer.open({
            type: 2,
            title: "新增人员",
            area: ['800px', '600px'],
            fix: false, //不固定
            maxmin: false,
            content: "${ctx}/messageController/toUserList.action"
        });
    }
    function deleteCover() {
        $("input[name='apkUrl']").val("");
        $("input[name='apkName']").val("");
        $("#apkFile").hide();
    }
    var form = layui.form();
    //监听提交
    form.on('submit(demo1)', function (data) {
        if (data.field.apkUrl == "") {
            layui.layer.msg('请上传apk', {icon: 5});
            return;
        }
        $.ajax({
            type: 'post',
            url: '${ctx}/apkController/saveOrUpdate.action',
            data: data.field,
            dataType: "json",
            timeout: 10000,
            success: function (data) {
                if (data.code == 0) {
                    layui.layer.msg('操作成功', {icon: 1});
                    window.location.reload();
                }
            }
        });
        return false;
    });
    form.render();
</script>
</body>

</html>